home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / program / t_bcinfo.zip / TI728.ZIP / TI728.ASC
Text File  |  1992-02-25  |  11KB  |  397 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.   PRODUCT  :  Borland C++                            NUMBER  :  728
  8.   VERSION  :  2.0
  9.        OS  :  DOS
  10.      DATE  :  February 25, 1992                        PAGE  :  1/6
  11.  
  12.     TITLE  :  Issues with Petzold's Programming Windows and Borland
  13.               C++
  14.  
  15.  
  16.  
  17.  
  18.   COMPILING IN C++
  19.   ----------------
  20.   When using Borland C++, problems with the examples from Charles
  21.   Petzold's Programming Windows will often result from compiling
  22.   them unmodified in C++ mode.  Here are some symptoms of this
  23.   problem which you may run across when compiling the examples from
  24.   Programming Windows:
  25.  
  26.      1.  HELLOWIN example does not display the text until it is
  27.          painted a second time
  28.  
  29.      2.  KEYLOOK example hangs with hourglass
  30.  
  31.      3.  CLOVER example does not print anything
  32.  
  33.      4.  GetSystemMetrics (or other API functions) give unusual
  34.          results
  35.  
  36.   The quick and obvious solution to this problem is to switch the
  37.   compiler back to C mode.  However, it IS quite possible to
  38.   compile these programs in C++ by making some minor modifications.
  39.  
  40.   The Petzold DEF files do not contain the C++ name mangled names
  41.   for the exported functions.  If the programs are to be compiled
  42.   as C++, the _export modifier should be used for any functions to
  43.   be exported.  The function entries in the EXPORTS section of the
  44.   DEF file can then be removed.  Following this method, the
  45.   declaration for a sample exported function would be:
  46.  
  47.   long  FAR PASCAL _export WndProc (HWND, WORD, WORD, LONG) ;
  48.  
  49.   An alternative way to export the functions would be to leave the
  50.   EXPORTS entry in the DEF file as is and declare the function as
  51.   extern "C" in the C++ source code.  This will "turn off" name
  52.   mangling for that function and thus the identifier for that
  53.   function will match the one exported in the DEF file.  Following
  54.   this method, the declaration for a sample exported function would
  55.   be:
  56.  
  57.   extern "C" long  FAR PASCAL WndProc (HWND, WORD, WORD, LONG) ;
  58.  
  59.   COMPILING IN C
  60.   --------------
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.   PRODUCT  :  Borland C++                            NUMBER  :  728
  74.   VERSION  :  2.0
  75.        OS  :  DOS
  76.      DATE  :  February 25, 1992                        PAGE  :  2/6
  77.  
  78.     TITLE  :  Issues with Petzold's Programming Windows and Borland
  79.               C++
  80.  
  81.  
  82.  
  83.  
  84.   The same symptoms described in the section above can occur when
  85.   compiling in C mode if you have not included the program's .DEF
  86.   file when linking your program.  If you are using BC or BCX, this
  87.   means you need to have a project file that includes your .DEF
  88.   file in addition to your .C file (and .RC file if one exists).
  89.   If you are using BCC or BCCX and calling TLINK directly, this
  90.   means that you have forgotten to include the .DEF file on your
  91.   TLINK command line.  See the Borland C++ User's Guide for more
  92.   information on TLINK.
  93.  
  94.   SYSMETS EXAMPLE
  95.   ---------------
  96.   In the SYSMETS2 example (page 73), max and min can return
  97.   incorrect values because NUMLINE returns an unsigned int rather
  98.   than an int.
  99.  
  100.   The problem has to do with the NUMLINES macro defined at the top
  101.   of SYSMETS.H (page 59).  As required by ANSI, sizeof returns an
  102.   unsigned.  This, combined with the max and min macros, results in
  103.   nVscrollPos never appearing to be less than 0.  Changing the
  104.   NUMLINES macro to:
  105.  
  106.   #define NUMLINES  ((int)sizeof sysmetrics/(int) sizeof sysmetrics[0])
  107.  
  108.   will resolve this problem.
  109.  
  110.   In addition, it should be noted that the max and min macros are
  111.   not defined in the C++ language.  The reason for this omission is
  112.   to allow C++ programmers to overload the function names min and
  113.   max.  To compile this example as C++, the min and max macros
  114.   should be copied from windows.h directly into the SYSMETS2.C
  115.   source file.
  116.  
  117.   DDEPOP / SHOWPOP EXAMPLE
  118.   ------------------------
  119.   Line 573 of DDEPOP.C declares a character array in the function
  120.   PostDataMessage as follows:
  121.  
  122.   char    szPopulation [10];
  123.  
  124.   This line should read:
  125.  
  126.   char    szPopulation [11];
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.   PRODUCT  :  Borland C++                            NUMBER  :  728
  140.   VERSION  :  2.0
  141.        OS  :  DOS
  142.      DATE  :  February 25, 1992                        PAGE  :  3/6
  143.  
  144.     TITLE  :  Issues with Petzold's Programming Windows and Borland
  145.               C++
  146.  
  147.  
  148.  
  149.  
  150.   Without this modification, a UAE will occur when running its
  151.   client program SHOWPOP.EXE.
  152.  
  153.   Note that there is a similar declaration on line 239 in the
  154.   function ServerProc.  Do not confuse this declaration with the
  155.   one on line 573.  Since the array szPopulation is never used in
  156.   the function ServerProc, you may remove the declaration of
  157.   szPopulation from line 239.
  158.  
  159.   BTNLOOK EXAMPLE
  160.   ---------------
  161.   On line 24 of BTNLOOK.C, change BS_USERBUTTON to BS_OWNERDRAW.
  162.   BS_USERBUTTON is not a style documented by Microsoft for
  163.   Microsoft Windows 3.0.
  164.  
  165.   READ VERSUS _LREAD
  166.   ------------------
  167.   Microsoft Windows defines a set of functions for file management
  168.   which are separate from the file management functions used in
  169.   traditional DOS applications.  Microsoft C 6.0 happens to allow
  170.   the free mixture of Windows file handles created with OpenFile()
  171.   and standard DOS file handles created with open().  This
  172.   "feature" is undocumented and therefore not standard Windows
  173.   programming.  In Borland C++, Windows file handles and DOS file
  174.   handles are not the same and cannot be freely mixed in calls to
  175.   functions.
  176.  
  177.   Some of the Programming Windows examples make calls to OpenFile()
  178.   and use the resulting handle in a call to read().  To make such
  179.   examples work when compiling with Borland C++, it will be
  180.   necessary to commit your program to one system of file management
  181.   or the other.  If you choose to use OpenFile(), calls to read()
  182.   and write() should be converted to calls to _lread() and
  183.   _lwrite().   If you choose to continue with calls to read()
  184.   and write(), the call to OpenFile should be converted to a call
  185.   to open().
  186.  
  187.   MAKE FILES
  188.   ----------
  189.   The make files provided for the examples in Programming Windows
  190.   were designed with Microsoft C in mind and are not compatible
  191.   with Borland C++.  Here is an example Borland makefile which can
  192.   be used for the simpler single file Windows programs.
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.   PRODUCT  :  Borland C++                            NUMBER  :  728
  206.   VERSION  :  2.0
  207.        OS  :  DOS
  208.      DATE  :  February 25, 1992                        PAGE  :  4/6
  209.  
  210.     TITLE  :  Issues with Petzold's Programming Windows and Borland
  211.               C++
  212.  
  213.  
  214.  
  215.  
  216.   --- cut here ---
  217.   #
  218.   # Borland C++ makefile for Charles Petzold's Programming Windows
  219.   # examples
  220.   #
  221.   #      Instructions:  1) Change "file" to the name of the example
  222.   #                        program being compiled.
  223.   #                     2) If the example you are compiling does
  224.   #                        not have an RC file, remove all
  225.   #                        references to "file.res".
  226.   #                     3) Modifications will be necessary for
  227.   #                        multifile examples.  Consult the
  228.   #                        Borland C++ User's Guide.
  229.   #
  230.   file.exe : file.obj file.def file.res
  231.           bccx -W file.obj
  232.           rc file.res file.exe
  233.           # if the example does not contain an RC file, remove
  234.           # "file.res" from the line above
  235.  
  236.   file.obj : file.c
  237.           bccx -W -c file.c
  238.  
  239.   # if the example does not contain an RC file, remove the rule
  240.   # below
  241.   file.res :
  242.           rc -r file.rc
  243.  
  244.   --- cut here ---
  245.  
  246.   Note that a DEF file called file.def would be linked in
  247.   automatically.  If file.def does not exist, default values would
  248.   be used.
  249.  
  250.   More complex, multifile examples are most easily built using the
  251.   project manager of BCX or BC.  Select "Open Project" from the
  252.   "Project" menu.  Give your project a name (this will also be the
  253.   name of your executable).  A project window will appear.  Select
  254.   the project window and hit the "insert" key.  You will be
  255.   prompted for the names of the source files to be included in your
  256.   project.  Also remember to include your RC file and your DEF file
  257.   in your project.  After all items are entered into your project,
  258.   select "Windows App" under the "Options | Application" menu.  You
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.   PRODUCT  :  Borland C++                            NUMBER  :  728
  272.   VERSION  :  2.0
  273.        OS  :  DOS
  274.      DATE  :  February 25, 1992                        PAGE  :  5/6
  275.  
  276.     TITLE  :  Issues with Petzold's Programming Windows and Borland
  277.               C++
  278.  
  279.  
  280.  
  281.  
  282.   may now compile the program by selecting "Build All" from the
  283.   "Compile" menu.
  284.  
  285.   If you require or prefer to use a make file rather than the
  286.   project manager, the utility PRJ2MAK can be used to convert the
  287.   project file described above into a Borland Make-compatible make
  288.   file.
  289.  
  290.   More information on Borland Make and the Project Manager can be
  291.   found in the Borland C++ User's Guide.  Information on PRJ2MAK
  292.   can be found in the document UTIL.DOC which you can find in your
  293.   DOC subdirectory of Borland C++.
  294.  
  295.   WARNINGS
  296.   --------
  297.   Many of the examples in Programming Windows will issue warnings
  298.   which can be ignored, such as the following:
  299.  
  300.   Warning file.c 57: Parameter 'lpszCmdParam' is never used in
  301.   function WinMain(unsigned int,unsigned int,char far*,int)
  302.  
  303.   The compiler correctly flags an unused parameter as a potential
  304.   problem in the code.  In most programs, it would be wasteful to
  305.   define a function which is passed parameters which are never
  306.   used.  However, the parameters for a Windows call back function
  307.   must all be declared so that Windows can pass messages to your
  308.   program.
  309.  
  310.   This warning message can be eliminated by inserting the line:
  311.  
  312.   #pragma argsused
  313.  
  314.   right before the declaration of the function.
  315.  
  316.   Another common warning is the following:
  317.  
  318.   Warning: Attempt to export non-public symbol WndProc
  319.  
  320.   This indicates that there is a function exported in your DEF file
  321.   which was not found in your program by the linker.  This warning
  322.   should not be ignored since, in many cases, attempting to export
  323.   a nonexistent symbol implies that you may have missed exporting a
  324.   symbol which DOES exist.  It may be that you are compiling your
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.   PRODUCT  :  Borland C++                            NUMBER  :  728
  338.   VERSION  :  2.0
  339.        OS  :  DOS
  340.      DATE  :  February 25, 1992                        PAGE  :  6/6
  341.  
  342.     TITLE  :  Issues with Petzold's Programming Windows and Borland
  343.               C++
  344.  
  345.  
  346.  
  347.  
  348.   program in C++ without modifying the example (see "COMPILING IN
  349.   C++" at the top of this document).
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.